package self.hoy.demo.grainmall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * redis/cache 配置
 *
 */
@Configuration
public class MyRedissonConfiguration {

    @Value("${spring.redis.host:127.0.0.1}")
    private String host;

    @Value("${spring.redis.port:16379}")
    private Integer port;

    @Value("${spring.redis.password:}")
    private String password;

    /**
     * 所有对redis的使用，都通过 redis client 对象
     * @return
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        Config config = new Config();
        // 集群模式
//        config.useClusterServers()
//                .addNodeAddress("127.0.0.1:7001", "127.0.0.1:7004");
        config.useSingleServer().setAddress("redis://" + host + ":" + port);
        return Redisson.create(config);
    }


}
